package cn.ainit.sys.config.thread;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import cn.ainit.sys.common.dao.SysBaseDao;

@Repository
public class TaskDaoImpl extends SysBaseDao implements TaskDao{
	
	@Override
	public void startRW() throws Exception {
		Connection conn = null;
		CallableStatement callStmt = null;
		String tproc_id = "";
		try {
			conn = this.getJdbcTemplate().getDataSource().getConnection();
			String callName = "";
			//查询所有的存储过程，执行
			String procsSql = "SELECT * FROM SYS_TASK_PRODUCE_THREAD";
			List<Map<String, Object>> procsList = this.getJdbcTemplate().queryForList(procsSql);
			String tmpProc = "";
			if (procsList != null) {
				for(int i = 0; i < procsList.size(); i ++){
					tproc_id = procsList.get(i).get("T_ID").toString();
					tmpProc = procsList.get(i).get("PROC_NAME").toString();
					callName = "{call "+tmpProc+"}";
					callStmt = conn.prepareCall(callName);
					callStmt.execute();
				}
			}
		} catch (Exception e) {
			System.err.print("作业存储执行错误，在表[SYS_TASK_PRODUCE_THREAD]中");
			e.printStackTrace();
		}finally{
			if (callStmt != null) {
				callStmt.close();
			}
			if (conn!= null) {
				conn.close();
			}
		}
	}
}
